/* h5列表数据
 * H5DataList.js
 */
import { combineReducers } from 'redux';

function loadingData(state=false,action){
	switch (action.type) {
		case 'H5_LIST_DATA':
			return false;
		case 'H5_LIST_DATA_START':
			return true;
		case 'H5_LIST_DATA_END':
			return false;	
	   	default:
		   	return state;
  	}
}

function datalist(state=Immutable.List(),action){
	switch (action.type) {
		case 'H5_LIST_DATA':
			//return Immutable.fromJS(action.datalist);
			let oriList=state;
			action.datalist.map(item=>{
				oriList=oriList.push(Immutable.Map(item));
			});
			return oriList;
		case 'H5_DETELE_H5_PAGE':
			let newlist=Immutable.List();
			const deleteId=action.id;
			state.forEach(item=>{
				if(item.get('id')!=deleteId){
					newlist=newlist.push(item);
				}
			});
			return newlist;
		case 'H5_UPDATE_TITLE':
			let newlist2=Immutable.List();
			state.forEach(item=>{
				if(item.get('id')!=action.id){
					newlist2=newlist2.push(item);
				}else{
					const newItem=item.set('title',action.title);
					newlist2=newlist2.push(newItem);
				}
			});
			return newlist2;
		case 'CLEAR_H5_LIST_DATA':
			return Immutable.List();
	   	default:
		   	return state;
  	}
}

function h5TplCategoryList(state=[],action){
	switch (action.type) {
		case 'H5TPL_CATEGORY_LIST':
			return action.datalist;
		default:
			return state;
	}
}

export default combineReducers({datalist,loadingData,h5TplCategoryList});
